﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.Platform.Core;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core.UI;
using Telerik.Windows.Controls;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Controls;
using System.Windows.Data;
using Baosight.Platform.Core.UI;
using Baosight.Platform.Core.ServiceModel;
using Microsoft.Practices.Unity;
using Baosight.ZNH.ZMCA.UI.Utils;
using Baosight.ZNH.ZMCommon;

namespace Baosight.ZNH.ZMCA.UI.PopWindows
{
    /// <summary>
    /// 生产问题详细信息
    /// </summary>
    public partial class ShowProduceProblem : EFViewCmes
    {
        public event EventHandler DataChanged;
        public ShowProduceProblem()
        {
            InitializeComponent();
            //this.Loaded += new RoutedEventHandler(ZMCA46_Loaded);
        }
        public void ZMCA46LoadData()
        {
            //Combobox等页面元素的初始化，传递查询条件，显示查询结果
            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service","ZMCA42");
            eiInfo.Set("method","initDataZMCA46");

            eiInfo.AddBlock(addBlock());

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo,onInitDataCompleted);
        }

        public EIBlock addBlock()
        {
            EIBlock block = new EIBlock("inqu");
            EIRow row = new EIRow();
            EIColumn column = new EIColumn();
            column.SetName("fdKeyId");
            block.AddColumn(column);
            row.Add("fdKeyId", fdKeyId.Value.ToString());
            block.AddRow(row);
            return block;
        }

        private void onInitDataCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.GetStatus() == -1)
            {
                EFWindow.Alert("数据加载失败！");
                return;
            }
            else
            {
                e.EIInfo.AddBlock(getProblemOrigin());
                e.EIInfo.AddBlock(getProblemStatus());
                this.UpdateData(e.EIInfo);
                queryEFGrid();
                return;
            }
        }
        //1代表生产问题
        public void queryEFGrid()
        {
            Dictionary<string, string> args = new Dictionary<string, string>();
            args.Add("fdKeyId", fdKeyId.Value.ToString());
            args.Add("fdProblemTypeId", "1");
            this.container.LoadView<EFCustomViewContainerPanel>("ZMCA49", args);
        }
        /// <summary>
        /// 下达指示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandClick(object sender, RoutedEventArgs e)
        {
            EFWindow window = new EFWindow();
            window.Header = "下达工作指示";
            ZMCA45 content = new ZMCA45();
            content.SaveSuccess += new EventHandler(content_SaveSuccess);
            content.fdKeyId.Value = fdKeyId.Value.ToString();
            content.fdProblemTypeId.Value = "1";
            content.SetNew();
            content.ZMCA45_Loaded(sender, e);
            window.Content = content;
            window.ShowDialog();
        }

        void content_SaveSuccess(object sender, EventArgs e)
        {
            if (DataChanged != null)
            {
                DataChanged(sender, e);
            }
        }

        /// <summary>
        /// 构造问题来源的下拉框数据
        /// </summary>
        public EIBlock getProblemOrigin()
        {
            EIBlock block = new EIBlock("cmes.cp.problemOrigin");

            EIColumn eiColumn = new EIColumn();
            eiColumn.Name = "display";
            eiColumn.TypeLabel = "C";
            block.AddColumn(eiColumn);

            eiColumn = new EIColumn();
            eiColumn.Name = "value";
            eiColumn.SetTypeLabel("C");
            block.AddColumn(eiColumn);

            IList<EIRow> _list = new List<EIRow>();
            EIRow _map = new EIRow();
            _map.Add("value", "0");
            _map.Add("display", "调度录入");
            _list.Add(_map);

            _map = new EIRow();
            _map.Add("value", "1");
            _map.Add("display", "班组汇报");
            _list.Add(_map);

            _map = new EIRow();
            _map.Add("value", "2");
            _map.Add("display", "领导提出");
            _list.Add(_map);

            block.AddRows(_list);
            return block;
        }

        /// <summary>
        /// 构造问题解决状态的下拉框数据
        /// </summary>
        public EIBlock getProblemStatus()
        {
            EIBlock block = new EIBlock("cmes.cp.problemStatus");

            EIColumn eiColumn = new EIColumn();
            eiColumn.Name = "value";
            eiColumn.TypeLabel = "C";
            block.AddColumn(eiColumn);

            eiColumn = new EIColumn();
            eiColumn.Name = "display";
            eiColumn.SetTypeLabel("C");
            block.AddColumn(eiColumn);

            IList<EIRow> _list = new List<EIRow>();
            EIRow _map = new EIRow();
            _map.Add("value", "0");
            _map.Add("display", "未解决");
            _list.Add(_map);

            _map = new EIRow();
            _map.Add("value", "1");
            _map.Add("display", "未核查");
            _list.Add(_map);

            _map = new EIRow();
            _map.Add("value", "2");
            _map.Add("display", "关闭");
            _list.Add(_map);

            _map = new EIRow();
            _map.Add("value", "3");
            _map.Add("display", "作废");
            _list.Add(_map);

            block.AddRows(_list);
            return block;
        }
    }
}
